﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace GameProject
{
    class Map
    {
        private Texture2D mapSprite;
        private Vector2 mapSpritePosition;
        private Rectangle mapEdgeLeft = new Rectangle(-2, -2, 4, 803);
        private Rectangle mapEdgeTop = new Rectangle(-2, -2, 1005, 4);
        private Rectangle mapEdgeRight = new Rectangle(999, -2, 4, 803);
        private Rectangle mapEdgeBottom = new Rectangle(-2, 799, 1005, 4);

        private Rectangle topLeftSquare = new Rectangle(0, 0, 348, 348);
        private Rectangle topRightSquare = new Rectangle(652, 0, 348, 348);
        private Rectangle bottomLeftSquare = new Rectangle(0, 652, 348, 148);
        private Rectangle bottomRightSquare = new Rectangle(652, 652, 348, 148);
        
        public void Initialize()
        {
            mapSpritePosition = new Vector2(0, 0);
        }
        public void LoadContent(ContentManager Content)
        {
            mapSprite = Content.Load<Texture2D>("gameBoard");

        }
        public void Draw(SpriteBatch spriteBatch)
        {
            spriteBatch.Draw(mapSprite,mapSpritePosition,Color.White);
        }
       
        public bool checkCollision(float x, float y, Rectangle rectangle)
        {
            if ((x < rectangle.X || y < rectangle.Y || x > (rectangle.X + rectangle.Width) 
                || y > (rectangle.Y + rectangle.Height)) && (x + 25 < rectangle.X || y + 25 < rectangle.Y 
                || x + 25 > (rectangle.X + rectangle.Width) || y + 25 > (rectangle.Y + rectangle.Height)) 
                && (x + 25 < rectangle.X || y < rectangle.Y || x + 25 > (rectangle.X + rectangle.Width) 
                || y > (rectangle.Y + rectangle.Height)) && (x < rectangle.X || y + 25 < rectangle.Y 
                || x > (rectangle.X + rectangle.Width) || y + 25 > (rectangle.Y + rectangle.Height)))
                return true;
            else
                return false;
        }
        public bool checkCollisionAll(float x, float y)
        {
            bool test1 = checkCollision(x, y, mapEdgeLeft);
            bool test2 = checkCollision(x, y, mapEdgeTop);
            bool test3 = checkCollision(x, y, mapEdgeRight);
            bool test4 = checkCollision(x, y, mapEdgeBottom);
            bool test5 = checkCollision(x, y, topLeftSquare);
            bool test6 = checkCollision(x, y, topRightSquare);
            bool test7 = checkCollision(x, y, bottomLeftSquare);
            bool test8 = checkCollision(x, y, bottomRightSquare);
            return (test1 && test2 && test3 && test4 && test5 && test6 && test7 && test8);
        }
    }
}
